package atguigu2.pool;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @AUTHOR LYF
 * @DATE 2022/2/4
 * @VERSION 1.0
 * @DESC
 */
public class ThreadPoolExecutorDemo {
    public static void main(String[] args) {

        // 创建线程池
        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(
                2,
                5,
                2L,
                TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(5),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy()
        );

        // 处理任务

        for (int i = 0; i < 10; i++) {
            final int num = i;
            threadPoolExecutor.execute(()->{
                System.out.println(Thread.currentThread().getName()+"办理业务"+num);
            });
        }
        threadPoolExecutor.shutdown();
    }
}
